#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
int T;
ll n,m,L,V;
ll sum;
ll dis[maxn];
struct car{
    int d,v,a;
}arr[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        sum=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>arr[i].d>>arr[i].v>>arr[i].a;
        }
        ll maxn=0;
        for(int i=1;i<=m;i++){
            cin>>dis[i];
            maxn=max(dis[i],maxn);
        }
        for(int i=1;i<=n;i++){
            if(arr[i].v>V){
                if(maxn>=arr[i].d) sum++;
        }
    }
    cout<<sum<<' ';
    if(sum==0) cout<<m;
    else cout<<m-1;
    cout<<endl;
    }
    return 0;
}
